package com.yjf.ljr.view;

import java.io.File;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.view.View;

import com.yjf.ljr.R;
import com.yjf.ljr.common.CommonData;

public class PhotoDialog extends Dialog {

	protected Activity mContext;
	public static String mFilePath = CommonData.AVATAR_DIR_SD + "/";// 头像存储路径
	public String storeFile;

	public PhotoDialog(Activity context) {
		super(context, R.style.dialog);
		this.mContext = context;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.photodialog);
		setCanceledOnTouchOutside(true);
		findViewById(R.id.btndelete_photodialog).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				dismiss();
			}
		});
		findViewById(R.id.radiobtn_album_photodialog).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
				if(TextUtils.isEmpty(storeFile)) {
					intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mFilePath, CommonData.USERID + ".jpg")));
				} else {
					intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(storeFile)));
				}				
				mContext.startActivityForResult(intent, CommonData.PHOTOHRAPH);
				dismiss();
			}
		});
		findViewById(R.id.radiobtn_picture_photodialog).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(Intent.ACTION_PICK, null);
				intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, CommonData.IMAGE_UNSPECIFIED);
				mContext.startActivityForResult(intent, CommonData.PHOTOZOOM);
				dismiss();
			}
		});
	}

	public void setCaptureFile(String storeFile ) {
		this.storeFile = storeFile;
	}
	
	public String getCaptureFilePath() {
		return this.storeFile;
	}
}
